package com.qf.proxy2;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
//JDK动态代理模板类(动态代理模板，生成代理对象)
//实现InvocationHandler类
public class MouseProxy implements InvocationHandler {
    //通过构造器获取鼠标工厂对象
    private MouseFactory mouseFactory;

    public MouseProxy(MouseFactory mouseFactory) {
        this.mouseFactory = mouseFactory;
    }

    //参数：proxy代理本身，method被代理的方法(工厂的方法)，args工厂方法的参数
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("售前服务");

        //通过反射调用执行工厂中的方法
        Object invoke = method.invoke(mouseFactory, args);

        System.out.println("售后服务");
        return invoke;
    }
}
